﻿using CommonUtils;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace Test.Core.Web.apis
{
    [Route("api/[controller]/[action]")]
    public class AjaxTestController : ControllerBase
    {
        [HttpPost]
        public ApiResult PostForm(string arg1, string arg2)
        {
            return ApiResult.Ok("arg1=" + arg1 + "&arg2=" + arg2);
        }

        [HttpPost]
        public ApiResult PostJson([FromBody] JToken json)
        {
            return ApiResult.Ok(json);
        }

        [HttpPost]
        public ApiResult PostText()
        {
            //asp.net.core.api 不支持 [FromBody]string，用 Request.GetBodyText() 代替
            var text = Request.GetBodyText();
            return ApiResult.Ok(text);
        }

        [HttpPost]
        public ApiResult PostNull()
        {
            return ApiResult.Ok();
        }
    }
}